<!DOCTYPE html>
<html lang="" xml:lang="">
<head>

  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title>Chapter 4 Methods | Venn Diagram cookbook in R</title>
  <meta name="description" content="How to draw Venn diagram with R packages." />
  <meta name="generator" content="bookdown 0.21 and GitBook 2.6.7" />

  <meta property="og:title" content="Chapter 4 Methods | Venn Diagram cookbook in R" />
  <meta property="og:type" content="book" />
  
  
  <meta property="og:description" content="How to draw Venn diagram with R packages." />
  

  <meta name="twitter:card" content="summary" />
  <meta name="twitter:title" content="Chapter 4 Methods | Venn Diagram cookbook in R" />
  
  <meta name="twitter:description" content="How to draw Venn diagram with R packages." />
  

<meta name="author" content="Chun-Hui Gao" />


<meta name="date" content="2021-05-11" />

  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  
  
<link rel="prev" href="using-ggVennDiagram.html"/>
<link rel="next" href="applications.html"/>
<script src="libs/header-attrs-2.7/header-attrs.js"></script>
<script src="libs/jquery-2.2.3/jquery.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />









<script src="libs/htmlwidgets-1.5.2/htmlwidgets.js"></script>
<script src="libs/plotly-binding-4.9.2.1/plotly.js"></script>
<script src="libs/typedarray-0.1/typedarray.min.js"></script>
<link href="libs/crosstalk-1.1.0.1/css/crosstalk.css" rel="stylesheet" />
<script src="libs/crosstalk-1.1.0.1/js/crosstalk.min.js"></script>
<link href="libs/plotly-htmlwidgets-css-1.52.2/plotly-htmlwidgets.css" rel="stylesheet" />
<script src="libs/plotly-main-1.52.2/plotly-latest.min.js"></script>


<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
  { counter-reset: source-line 0; }
pre.numberSource code > span
  { position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
  { content: counter(source-line);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
    color: #aaaaaa;
  }
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
div.sourceCode
  {   }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>

<link rel="stylesheet" href="style.css" type="text/css" />
</head>

<body>



  <div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">

    <div class="book-summary">
      <nav role="navigation">

<ul class="summary">
<li><a href="./">Venn Diagram in R</a></li>

<li class="divider"></li>
<li class="chapter" data-level="1" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i><b>1</b> Preface</a>
<ul>
<li class="chapter" data-level="1.1" data-path="index.html"><a href="index.html#prerequisites"><i class="fa fa-check"></i><b>1.1</b> Prerequisites</a></li>
<li class="chapter" data-level="1.2" data-path="index.html"><a href="index.html#sessioninfo"><i class="fa fa-check"></i><b>1.2</b> Sessioninfo</a></li>
</ul></li>
<li class="chapter" data-level="2" data-path="intro.html"><a href="intro.html"><i class="fa fa-check"></i><b>2</b> Introduction</a>
<ul>
<li class="chapter" data-level="2.1" data-path="intro.html"><a href="intro.html#venndiagram"><i class="fa fa-check"></i><b>2.1</b> <code>VennDiagram</code></a></li>
<li class="chapter" data-level="2.2" data-path="intro.html"><a href="intro.html#colorfulvennplot"><i class="fa fa-check"></i><b>2.2</b> <code>colorfulVennPlot</code></a></li>
<li class="chapter" data-level="2.3" data-path="intro.html"><a href="intro.html#venn"><i class="fa fa-check"></i><b>2.3</b> <code>venn</code></a></li>
<li class="chapter" data-level="2.4" data-path="intro.html"><a href="intro.html#nvennr"><i class="fa fa-check"></i><b>2.4</b> <code>nVennR</code></a></li>
<li class="chapter" data-level="2.5" data-path="intro.html"><a href="intro.html#eulerr"><i class="fa fa-check"></i><b>2.5</b> <code>eulerr</code></a></li>
<li class="chapter" data-level="2.6" data-path="intro.html"><a href="intro.html#venneuler"><i class="fa fa-check"></i><b>2.6</b> <code>venneuler</code></a></li>
<li class="chapter" data-level="2.7" data-path="intro.html"><a href="intro.html#rvenn"><i class="fa fa-check"></i><b>2.7</b> <code>RVenn</code></a></li>
<li class="chapter" data-level="2.8" data-path="intro.html"><a href="intro.html#gplots"><i class="fa fa-check"></i><b>2.8</b> <code>gplots</code></a></li>
<li class="chapter" data-level="2.9" data-path="intro.html"><a href="intro.html#ggvenndiagram"><i class="fa fa-check"></i><b>2.9</b> <code>ggVennDiagram</code></a></li>
<li class="chapter" data-level="2.10" data-path="intro.html"><a href="intro.html#ggvenn"><i class="fa fa-check"></i><b>2.10</b> <code>ggvenn</code></a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="using-ggVennDiagram.html"><a href="using-ggVennDiagram.html"><i class="fa fa-check"></i><b>3</b> Using <code>ggVennDiagram</code></a>
<ul>
<li class="chapter" data-level="3.1" data-path="using-ggVennDiagram.html"><a href="using-ggVennDiagram.html#long-category-names"><i class="fa fa-check"></i><b>3.1</b> long category names</a></li>
<li class="chapter" data-level="3.2" data-path="using-ggVennDiagram.html"><a href="using-ggVennDiagram.html#show-intersection-values"><i class="fa fa-check"></i><b>3.2</b> Show intersection values</a></li>
<li class="chapter" data-level="3.3" data-path="using-ggVennDiagram.html"><a href="using-ggVennDiagram.html#setting-set-label"><i class="fa fa-check"></i><b>3.3</b> Setting set label</a>
<ul>
<li class="chapter" data-level="3.3.1" data-path="using-ggVennDiagram.html"><a href="using-ggVennDiagram.html#color-of-set-label"><i class="fa fa-check"></i><b>3.3.1</b> color of set label</a></li>
<li class="chapter" data-level="3.3.2" data-path="using-ggVennDiagram.html"><a href="using-ggVennDiagram.html#size-of-set-labels"><i class="fa fa-check"></i><b>3.3.2</b> size of set labels</a></li>
</ul></li>
<li class="chapter" data-level="3.4" data-path="using-ggVennDiagram.html"><a href="using-ggVennDiagram.html#setting-region-label"><i class="fa fa-check"></i><b>3.4</b> Setting region label</a>
<ul>
<li class="chapter" data-level="3.4.1" data-path="using-ggVennDiagram.html"><a href="using-ggVennDiagram.html#text-content"><i class="fa fa-check"></i><b>3.4.1</b> text content</a></li>
<li class="chapter" data-level="3.4.2" data-path="using-ggVennDiagram.html"><a href="using-ggVennDiagram.html#percentage-digits"><i class="fa fa-check"></i><b>3.4.2</b> percentage digits</a></li>
<li class="chapter" data-level="3.4.3" data-path="using-ggVennDiagram.html"><a href="using-ggVennDiagram.html#remove-label-background"><i class="fa fa-check"></i><b>3.4.3</b> remove label background</a></li>
<li class="chapter" data-level="3.4.4" data-path="using-ggVennDiagram.html"><a href="using-ggVennDiagram.html#color-and-size"><i class="fa fa-check"></i><b>3.4.4</b> color and size</a></li>
</ul></li>
<li class="chapter" data-level="3.5" data-path="using-ggVennDiagram.html"><a href="using-ggVennDiagram.html#setting-set-edges"><i class="fa fa-check"></i><b>3.5</b> Setting set edges</a></li>
<li class="chapter" data-level="3.6" data-path="using-ggVennDiagram.html"><a href="using-ggVennDiagram.html#changing-palette"><i class="fa fa-check"></i><b>3.6</b> Changing palette</a></li>
<li class="chapter" data-level="3.7" data-path="using-ggVennDiagram.html"><a href="using-ggVennDiagram.html#adding-note"><i class="fa fa-check"></i><b>3.7</b> Adding note</a></li>
<li class="chapter" data-level="3.8" data-path="using-ggVennDiagram.html"><a href="using-ggVennDiagram.html#comprehensive-customization-by-using-helper-functions"><i class="fa fa-check"></i><b>3.8</b> Comprehensive customization by using helper functions</a></li>
</ul></li>
<li class="chapter" data-level="4" data-path="methods.html"><a href="methods.html"><i class="fa fa-check"></i><b>4</b> Methods</a>
<ul>
<li class="chapter" data-level="4.1" data-path="methods.html"><a href="methods.html#predefined-sysdata-in-venn"><i class="fa fa-check"></i><b>4.1</b> Predefined <code>sysdata</code> in <code>venn</code></a></li>
<li class="chapter" data-level="4.2" data-path="methods.html"><a href="methods.html#set-operation-in-rvenn"><i class="fa fa-check"></i><b>4.2</b> Set operation in <code>RVenn</code></a>
<ul>
<li class="chapter" data-level="4.2.1" data-path="methods.html"><a href="methods.html#set-operations-in-rvenn"><i class="fa fa-check"></i><b>4.2.1</b> Set operations in <code>RVenn</code></a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="5" data-path="applications.html"><a href="applications.html"><i class="fa fa-check"></i><b>5</b> Applications of Venn, Euler and Upset plot</a></li>
<li class="chapter" data-level="6" data-path="conclusion.html"><a href="conclusion.html"><i class="fa fa-check"></i><b>6</b> Conclusion</a></li>
<li class="chapter" data-level="" data-path="references.html"><a href="references.html"><i class="fa fa-check"></i>References</a></li>
<li class="divider"></li>
<li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>

</ul>

      </nav>
    </div>

    <div class="book-body">
      <div class="body-inner">
        <div class="book-header" role="navigation">
          <h1>
            <i class="fa fa-circle-o-notch fa-spin"></i><a href="./">Venn Diagram cookbook in R</a>
          </h1>
        </div>

        <div class="page-wrapper" tabindex="-1" role="main">
          <div class="page-inner">

            <section class="normal" id="section-">
<div id="methods" class="section level1" number="4">
<h1><span class="header-section-number">Chapter 4</span> Methods</h1>
<p><code>ggVennDiagram</code> is built on the shoulder of the other related R packages.
Except for <code>ggplot2</code>, it also depends on the functions in <code>dplyr</code>, <code>tibble</code>, <code>sf</code>, and so on.
Besides, the design of <code>ggVennDiagram</code> version 1.0 is inspired by two packages,
<code>venn</code> and <code>RVenn</code>.</p>
<div id="predefined-sysdata-in-venn" class="section level2" number="4.1">
<h2><span class="header-section-number">4.1</span> Predefined <code>sysdata</code> in <code>venn</code></h2>
<p><code>venn::venn()</code> support Venn diagram up to 7 sets.</p>
<p>It use predefined values to plot polygons.</p>
<div class="sourceCode" id="cb57"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb57-1"><a href="methods.html#cb57-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(dplyr)</span>
<span id="cb57-2"><a href="methods.html#cb57-2" aria-hidden="true" tabindex="-1"></a>sets <span class="ot">&lt;-</span> venn<span class="sc">:::</span>sets</span>
<span id="cb57-3"><a href="methods.html#cb57-3" aria-hidden="true" tabindex="-1"></a><span class="fu">glimpse</span>(sets)</span></code></pre></div>
<pre><code>## Rows: 9,536
## Columns: 5
## $ s &lt;int&gt; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,...
## $ v &lt;int&gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,...
## $ n &lt;int&gt; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,...
## $ x &lt;dbl&gt; 500.000, 493.573, 487.185, 480.838, 474.533, 468.273, 462.059, 45...
## $ y &lt;dbl&gt; 750.000, 749.918, 749.673, 749.267, 748.703, 747.982, 747.106, 74...</code></pre>
<ul>
<li>s: number of sets;</li>
<li>v: whether it is for ellipse;</li>
<li>n: No. of polygons;</li>
</ul>
<p>The following is a visualization of <code>venn</code> predefined polygons.
These polygons can’t be generated using simple functions, but are painstaking manual work
that took years to create. I have communicated with the author of <code>venn</code>, Prof. Adrian Dușa,
and get his consent to reuse these data.</p>
<div class="sourceCode" id="cb59"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb59-1"><a href="methods.html#cb59-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(ggplot2)</span>
<span id="cb59-2"><a href="methods.html#cb59-2" aria-hidden="true" tabindex="-1"></a><span class="fu">ggplot</span>(sets, <span class="fu">aes</span>(x,y)) <span class="sc">+</span> </span>
<span id="cb59-3"><a href="methods.html#cb59-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_polygon</span>(<span class="fu">aes</span>(<span class="at">color=</span><span class="fu">factor</span>(n)),<span class="at">alpha=</span><span class="dv">1</span><span class="sc">/</span><span class="dv">5</span>) <span class="sc">+</span> </span>
<span id="cb59-4"><a href="methods.html#cb59-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">facet_grid</span>(v<span class="sc">~</span>s) <span class="sc">+</span> </span>
<span id="cb59-5"><a href="methods.html#cb59-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">coord_fixed</span>() <span class="sc">+</span></span>
<span id="cb59-6"><a href="methods.html#cb59-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme_void</span>() <span class="sc">+</span></span>
<span id="cb59-7"><a href="methods.html#cb59-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme</span>(<span class="at">legend.position =</span> <span class="st">&quot;none&quot;</span>)</span></code></pre></div>
<p><img src="ggVennDiagramPaper_files/figure-html/unnamed-chunk-47-1.png" width="90%" /></p>
<p>In <code>ggVennDiagram</code>, we also store a predefined shapes in <code>sysdata</code>, and this
will no doubt improve shape generations in user-side.
You may navigate the shape data with <code>get_shape_data()</code> function.</p>
<div class="sourceCode" id="cb60"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb60-1"><a href="methods.html#cb60-1" aria-hidden="true" tabindex="-1"></a>ggVennDiagram<span class="sc">::</span><span class="fu">get_shape_data</span>(<span class="dv">4</span>)</span></code></pre></div>
<pre><code>## # A tibble: 8 x 6
##   nsets type    shape_id component id    xy                 
##   &lt;dbl&gt; &lt;chr&gt;   &lt;chr&gt;    &lt;chr&gt;     &lt;chr&gt; &lt;list&gt;             
## 1     4 ellipse 401f     setEdge   1     &lt;dbl[,2] [101 x 2]&gt;
## 2     4 ellipse 401f     setEdge   2     &lt;dbl[,2] [101 x 2]&gt;
## 3     4 ellipse 401f     setEdge   3     &lt;dbl[,2] [101 x 2]&gt;
## 4     4 ellipse 401f     setEdge   4     &lt;dbl[,2] [101 x 2]&gt;
## 5     4 ellipse 401f     setLabel  1     &lt;dbl[,2] [1 x 2]&gt;  
## 6     4 ellipse 401f     setLabel  2     &lt;dbl[,2] [1 x 2]&gt;  
## 7     4 ellipse 401f     setLabel  3     &lt;dbl[,2] [1 x 2]&gt;  
## 8     4 ellipse 401f     setLabel  4     &lt;dbl[,2] [1 x 2]&gt;</code></pre>
<p>or plot them with <code>plot_shapes()</code>.</p>
<div class="sourceCode" id="cb62"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb62-1"><a href="methods.html#cb62-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot_shapes</span>() </span></code></pre></div>
<p><img src="ggVennDiagramPaper_files/figure-html/unnamed-chunk-49-1.png" width="90%" /></p>
</div>
<div id="set-operation-in-rvenn" class="section level2" number="4.2">
<h2><span class="header-section-number">4.2</span> Set operation in <code>RVenn</code></h2>
<p><code>RVenn</code> defines a S4 class object <code>Venn</code> to store members of Venn sets.</p>
<div class="sourceCode" id="cb63"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb63-1"><a href="methods.html#cb63-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(purrr)</span>
<span id="cb63-2"><a href="methods.html#cb63-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(RVenn)</span>
<span id="cb63-3"><a href="methods.html#cb63-3" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(ggplot2)</span>
<span id="cb63-4"><a href="methods.html#cb63-4" aria-hidden="true" tabindex="-1"></a><span class="fu">ggVennDiagram</span>(gene_list)</span></code></pre></div>
<p><img src="ggVennDiagramPaper_files/figure-html/unnamed-chunk-50-1.png" width="90%" /></p>
<p>Construct the Venn object.</p>
<div class="sourceCode" id="cb64"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb64-1"><a href="methods.html#cb64-1" aria-hidden="true" tabindex="-1"></a>toy <span class="ot">&lt;-</span> <span class="fu">Venn</span>(gene_list)</span>
<span id="cb64-2"><a href="methods.html#cb64-2" aria-hidden="true" tabindex="-1"></a><span class="fu">glimpse</span>(toy)</span></code></pre></div>
<pre><code>## Formal class &#39;Venn&#39; [package &quot;RVenn&quot;] with 2 slots
##   ..@ sets :List of 4
##   .. ..$ A: chr [1:100] &quot;gene284&quot; &quot;gene106&quot; &quot;gene712&quot; &quot;gene905&quot; ...
##   .. ..$ B: chr [1:200] &quot;gene403&quot; &quot;gene644&quot; &quot;gene438&quot; &quot;gene29&quot; ...
##   .. ..$ C: chr [1:300] &quot;gene27&quot; &quot;gene788&quot; &quot;gene287&quot; &quot;gene361&quot; ...
##   .. ..$ D: chr [1:200] &quot;gene601&quot; &quot;gene165&quot; &quot;gene479&quot; &quot;gene390&quot; ...
##   ..@ names: chr [1:4] &quot;A&quot; &quot;B&quot; &quot;C&quot; &quot;D&quot;</code></pre>
<p>On this basis, it implements methods to calculate the intersection/overlapping/union
of different sets.</p>
<div id="set-operations-in-rvenn" class="section level3" number="4.2.1">
<h3><span class="header-section-number">4.2.1</span> Set operations in <code>RVenn</code></h3>
<ul>
<li><strong>Intersection</strong></li>
</ul>
<div class="sourceCode" id="cb66"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb66-1"><a href="methods.html#cb66-1" aria-hidden="true" tabindex="-1"></a><span class="co"># intersection</span></span>
<span id="cb66-2"><a href="methods.html#cb66-2" aria-hidden="true" tabindex="-1"></a><span class="fu">overlap</span>(toy)</span></code></pre></div>
<pre><code>## [1] &quot;gene757&quot;</code></pre>
<div class="sourceCode" id="cb68"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb68-1"><a href="methods.html#cb68-1" aria-hidden="true" tabindex="-1"></a><span class="fu">overlap</span>(toy, <span class="at">slice =</span> <span class="dv">1</span><span class="sc">:</span><span class="dv">3</span>)</span></code></pre></div>
<pre><code>## [1] &quot;gene876&quot; &quot;gene405&quot; &quot;gene361&quot; &quot;gene63&quot;  &quot;gene679&quot; &quot;gene757&quot;</code></pre>
<div class="sourceCode" id="cb70"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb70-1"><a href="methods.html#cb70-1" aria-hidden="true" tabindex="-1"></a><span class="fu">overlap</span>(toy, <span class="at">slice =</span> <span class="fu">c</span>(<span class="st">&quot;A&quot;</span>,<span class="st">&quot;B&quot;</span>,<span class="st">&quot;C&quot;</span>))</span></code></pre></div>
<pre><code>## [1] &quot;gene876&quot; &quot;gene405&quot; &quot;gene361&quot; &quot;gene63&quot;  &quot;gene679&quot; &quot;gene757&quot;</code></pre>
<ul>
<li><strong>Union</strong></li>
</ul>
<div class="sourceCode" id="cb72"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb72-1"><a href="methods.html#cb72-1" aria-hidden="true" tabindex="-1"></a><span class="fu">unite</span>(toy) <span class="sc">%&gt;%</span> <span class="fu">sort</span>()</span></code></pre></div>
<pre><code>##   [1] &quot;gene1&quot;   &quot;gene10&quot;  &quot;gene101&quot; &quot;gene102&quot; &quot;gene103&quot; &quot;gene104&quot; &quot;gene105&quot;
##   [8] &quot;gene106&quot; &quot;gene107&quot; &quot;gene110&quot; &quot;gene112&quot; &quot;gene114&quot; &quot;gene115&quot; &quot;gene116&quot;
##  [15] &quot;gene117&quot; &quot;gene118&quot; &quot;gene120&quot; &quot;gene121&quot; &quot;gene122&quot; &quot;gene125&quot; &quot;gene126&quot;
##  [22] &quot;gene127&quot; &quot;gene131&quot; &quot;gene133&quot; &quot;gene134&quot; &quot;gene136&quot; &quot;gene138&quot; &quot;gene140&quot;
##  [29] &quot;gene141&quot; &quot;gene145&quot; &quot;gene146&quot; &quot;gene147&quot; &quot;gene148&quot; &quot;gene150&quot; &quot;gene153&quot;
##  [36] &quot;gene155&quot; &quot;gene16&quot;  &quot;gene161&quot; &quot;gene163&quot; &quot;gene164&quot; &quot;gene165&quot; &quot;gene166&quot;
##  [43] &quot;gene167&quot; &quot;gene168&quot; &quot;gene169&quot; &quot;gene17&quot;  &quot;gene171&quot; &quot;gene173&quot; &quot;gene174&quot;
##  [50] &quot;gene176&quot; &quot;gene177&quot; &quot;gene18&quot;  &quot;gene180&quot; &quot;gene182&quot; &quot;gene183&quot; &quot;gene187&quot;
##  [57] &quot;gene188&quot; &quot;gene189&quot; &quot;gene19&quot;  &quot;gene195&quot; &quot;gene196&quot; &quot;gene197&quot; &quot;gene198&quot;
##  [64] &quot;gene199&quot; &quot;gene2&quot;   &quot;gene20&quot;  &quot;gene201&quot; &quot;gene203&quot; &quot;gene206&quot; &quot;gene207&quot;
##  [71] &quot;gene208&quot; &quot;gene209&quot; &quot;gene21&quot;  &quot;gene212&quot; &quot;gene213&quot; &quot;gene214&quot; &quot;gene215&quot;
##  [78] &quot;gene217&quot; &quot;gene218&quot; &quot;gene219&quot; &quot;gene22&quot;  &quot;gene220&quot; &quot;gene223&quot; &quot;gene224&quot;
##  [85] &quot;gene226&quot; &quot;gene227&quot; &quot;gene23&quot;  &quot;gene230&quot; &quot;gene234&quot; &quot;gene235&quot; &quot;gene237&quot;
##  [92] &quot;gene238&quot; &quot;gene241&quot; &quot;gene244&quot; &quot;gene245&quot; &quot;gene246&quot; &quot;gene247&quot; &quot;gene249&quot;
##  [99] &quot;gene25&quot;  &quot;gene250&quot;
##  [ reached getOption(&quot;max.print&quot;) -- omitted 501 entries ]</code></pre>
<ul>
<li><strong>Set difference</strong></li>
</ul>
<div class="sourceCode" id="cb74"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb74-1"><a href="methods.html#cb74-1" aria-hidden="true" tabindex="-1"></a><span class="fu">discern</span>(toy, <span class="at">slice1 =</span> <span class="dv">1</span><span class="sc">:</span><span class="dv">3</span>) <span class="sc">%&gt;%</span> <span class="fu">sort</span>()</span></code></pre></div>
<pre><code>##   [1] &quot;gene101&quot; &quot;gene104&quot; &quot;gene106&quot; &quot;gene107&quot; &quot;gene110&quot; &quot;gene112&quot; &quot;gene114&quot;
##   [8] &quot;gene115&quot; &quot;gene116&quot; &quot;gene117&quot; &quot;gene118&quot; &quot;gene121&quot; &quot;gene122&quot; &quot;gene126&quot;
##  [15] &quot;gene127&quot; &quot;gene133&quot; &quot;gene134&quot; &quot;gene136&quot; &quot;gene138&quot; &quot;gene140&quot; &quot;gene141&quot;
##  [22] &quot;gene146&quot; &quot;gene147&quot; &quot;gene148&quot; &quot;gene150&quot; &quot;gene153&quot; &quot;gene155&quot; &quot;gene16&quot; 
##  [29] &quot;gene161&quot; &quot;gene163&quot; &quot;gene164&quot; &quot;gene166&quot; &quot;gene167&quot; &quot;gene171&quot; &quot;gene174&quot;
##  [36] &quot;gene176&quot; &quot;gene177&quot; &quot;gene18&quot;  &quot;gene182&quot; &quot;gene183&quot; &quot;gene188&quot; &quot;gene19&quot; 
##  [43] &quot;gene197&quot; &quot;gene198&quot; &quot;gene199&quot; &quot;gene2&quot;   &quot;gene20&quot;  &quot;gene201&quot; &quot;gene209&quot;
##  [50] &quot;gene21&quot;  &quot;gene212&quot; &quot;gene213&quot; &quot;gene214&quot; &quot;gene215&quot; &quot;gene217&quot; &quot;gene219&quot;
##  [57] &quot;gene223&quot; &quot;gene224&quot; &quot;gene226&quot; &quot;gene227&quot; &quot;gene23&quot;  &quot;gene230&quot; &quot;gene234&quot;
##  [64] &quot;gene235&quot; &quot;gene238&quot; &quot;gene246&quot; &quot;gene25&quot;  &quot;gene250&quot; &quot;gene251&quot; &quot;gene252&quot;
##  [71] &quot;gene253&quot; &quot;gene254&quot; &quot;gene255&quot; &quot;gene263&quot; &quot;gene267&quot; &quot;gene268&quot; &quot;gene270&quot;
##  [78] &quot;gene272&quot; &quot;gene275&quot; &quot;gene277&quot; &quot;gene278&quot; &quot;gene279&quot; &quot;gene28&quot;  &quot;gene281&quot;
##  [85] &quot;gene284&quot; &quot;gene287&quot; &quot;gene289&quot; &quot;gene29&quot;  &quot;gene293&quot; &quot;gene295&quot; &quot;gene297&quot;
##  [92] &quot;gene298&quot; &quot;gene302&quot; &quot;gene303&quot; &quot;gene304&quot; &quot;gene305&quot; &quot;gene309&quot; &quot;gene31&quot; 
##  [99] &quot;gene310&quot; &quot;gene312&quot;
##  [ reached getOption(&quot;max.print&quot;) -- omitted 301 entries ]</code></pre>
<div class="sourceCode" id="cb76"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb76-1"><a href="methods.html#cb76-1" aria-hidden="true" tabindex="-1"></a><span class="fu">discern</span>(toy, <span class="at">slice1 =</span> <span class="dv">1</span><span class="sc">:</span><span class="dv">2</span>, <span class="at">slice2 =</span> <span class="dv">3</span><span class="sc">:</span><span class="dv">4</span>) <span class="sc">%&gt;%</span> <span class="fu">sort</span>()</span></code></pre></div>
<pre><code>##   [1] &quot;gene101&quot; &quot;gene104&quot; &quot;gene106&quot; &quot;gene112&quot; &quot;gene115&quot; &quot;gene122&quot; &quot;gene133&quot;
##   [8] &quot;gene134&quot; &quot;gene136&quot; &quot;gene146&quot; &quot;gene148&quot; &quot;gene161&quot; &quot;gene163&quot; &quot;gene164&quot;
##  [15] &quot;gene167&quot; &quot;gene174&quot; &quot;gene176&quot; &quot;gene177&quot; &quot;gene18&quot;  &quot;gene183&quot; &quot;gene188&quot;
##  [22] &quot;gene19&quot;  &quot;gene197&quot; &quot;gene2&quot;   &quot;gene209&quot; &quot;gene213&quot; &quot;gene217&quot; &quot;gene223&quot;
##  [29] &quot;gene226&quot; &quot;gene227&quot; &quot;gene238&quot; &quot;gene246&quot; &quot;gene251&quot; &quot;gene253&quot; &quot;gene267&quot;
##  [36] &quot;gene268&quot; &quot;gene284&quot; &quot;gene29&quot;  &quot;gene293&quot; &quot;gene303&quot; &quot;gene305&quot; &quot;gene314&quot;
##  [43] &quot;gene316&quot; &quot;gene319&quot; &quot;gene32&quot;  &quot;gene327&quot; &quot;gene328&quot; &quot;gene348&quot; &quot;gene349&quot;
##  [50] &quot;gene363&quot; &quot;gene364&quot; &quot;gene365&quot; &quot;gene373&quot; &quot;gene384&quot; &quot;gene386&quot; &quot;gene391&quot;
##  [57] &quot;gene400&quot; &quot;gene401&quot; &quot;gene403&quot; &quot;gene411&quot; &quot;gene416&quot; &quot;gene420&quot; &quot;gene424&quot;
##  [64] &quot;gene425&quot; &quot;gene428&quot; &quot;gene43&quot;  &quot;gene431&quot; &quot;gene435&quot; &quot;gene436&quot; &quot;gene438&quot;
##  [71] &quot;gene444&quot; &quot;gene458&quot; &quot;gene474&quot; &quot;gene475&quot; &quot;gene493&quot; &quot;gene5&quot;   &quot;gene50&quot; 
##  [78] &quot;gene500&quot; &quot;gene523&quot; &quot;gene530&quot; &quot;gene564&quot; &quot;gene566&quot; &quot;gene570&quot; &quot;gene574&quot;
##  [85] &quot;gene575&quot; &quot;gene580&quot; &quot;gene584&quot; &quot;gene588&quot; &quot;gene592&quot; &quot;gene597&quot; &quot;gene614&quot;
##  [92] &quot;gene626&quot; &quot;gene631&quot; &quot;gene650&quot; &quot;gene657&quot; &quot;gene662&quot; &quot;gene663&quot; &quot;gene680&quot;
##  [99] &quot;gene693&quot; &quot;gene695&quot;
##  [ reached getOption(&quot;max.print&quot;) -- omitted 52 entries ]</code></pre>
<p>In <code>ggVennDiagram</code>, region value calculation depends on the <code>RVenn</code> package and
new functions written on its defined Venn object.
There are totally <span class="math inline">\(2^n–1\)</span> regions in a Venn diagram, in which <span class="math inline">\(n\)</span> is the number of sets.
We developed <code>discern_overlap()</code> to calculate the members of every Venn regions.
By default, it will return the intersection of all the sets, which only contains one gene here.</p>
<div class="sourceCode" id="cb78"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb78-1"><a href="methods.html#cb78-1" aria-hidden="true" tabindex="-1"></a><span class="fu">discern_overlap</span>(toy)</span></code></pre></div>
<pre><code>## [1] &quot;gene757&quot;</code></pre>
<div class="sourceCode" id="cb80"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb80-1"><a href="methods.html#cb80-1" aria-hidden="true" tabindex="-1"></a><span class="fu">discern_overlap</span>(toy, <span class="at">slice =</span> <span class="dv">1</span><span class="sc">:</span><span class="dv">2</span>)</span></code></pre></div>
<pre><code>##  [1] &quot;gene712&quot; &quot;gene133&quot; &quot;gene931&quot; &quot;gene213&quot; &quot;gene747&quot; &quot;gene597&quot; &quot;gene268&quot;
##  [8] &quot;gene871&quot; &quot;gene197&quot; &quot;gene136&quot;</code></pre>
<p>We construct a <code>Polygon</code> object that inherits <code>Venn</code> to store shape data.
And expanded <code>discern_overlap()</code> method to calculate region shapes.
After calculation, the member and count of each region are stored with region ids in a tibble,
and then joined with the region shape object by unique ids. Likewise,
the member and count of sets are assigned to the <code>SetEdge</code> by unique ids in parallel.<br />
By doing this, a complete <code>VennPlotData</code> object is finished and can be used for plotting.</p>

</div>
</div>
</div>
<div id="disqus_thread"></div>
<script>
    /**
    *  RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
    *  LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables    */
    /*
    var disqus_config = function () {
    this.page.url = PAGE_URL;  // Replace PAGE_URL with your page's canonical URL variable
    this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
    };
    */
    (function() { // DON'T EDIT BELOW THIS LINE
    var d = document, s = d.createElement('script');
    s.src = 'https://venn-diagram-in-r.disqus.com/embed.js';
    s.setAttribute('data-timestamp', +new Date());
    (d.head || d.body).appendChild(s);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
            </section>

          </div>
        </div>
      </div>
<a href="using-ggVennDiagram.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="applications.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
    </div>
  </div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/lunr.js"></script>
<script src="libs/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": false,
"facebook": true,
"twitter": true,
"linkedin": false,
"weibo": false,
"instapaper": false,
"vk": false,
"all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": null,
"text": null
},
"history": {
"link": null,
"text": null
},
"view": {
"link": null,
"text": null
},
"download": ["ggVennDiagramPaper"],
"toc": {
"collapse": "subsection"
}
});
});
</script>

<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    var src = "true";
    if (src === "" || src === "true") src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML";
    if (location.protocol !== "file:")
      if (/^https?:/.test(src))
        src = src.replace(/^https?:/, '');
    script.src = src;
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>
</body>

</html>
